<template>
  <div>
    <div class="n-layout-page-header">
      <n-card :bordered="false" title="异动股票池">
        <!--  这是由系统生成的CURD表格，你可以将此行注释改为表格的描述 -->
      </n-card>
    </div>
    <n-card :bordered="false" class="proCard">
      <n-tabs type="line" animated>
        <n-tab-pane name="ztgc_em" tab="涨停股池">
          <BasicTable
            :openChecked="true"
            :columns="columns"
            :request="loadZTDataTable"
            :row-key="(row) => row.id"
            ref="actionRef"
            :actionColumn="false"
            :checked-row-keys="checkedIds"
            @update:checked-row-keys="onCheckedRow"
            :scroll-x="1090"
            :resizeHeightOffset="-10000"
            size="small"
          />
        </n-tab-pane>
        <n-tab-pane name="dtgc_em" tab="跌停股池">
          <BasicTable
            :openChecked="true"
            :columns="columns"
            :request="loadDTDataTable"
            :row-key="(row) => row.id"
            ref="actionRef"
            :actionColumn="false"
            :checked-row-keys="checkedIds"
            @update:checked-row-keys="onCheckedRow"
            :scroll-x="1090"
            :resizeHeightOffset="-10000"
            size="small"
          />
        </n-tab-pane>
        <n-tab-pane name="prevztgc_em" tab="昨日涨停池">
          <BasicTable
            :openChecked="true"
            :columns="columns"
            :request="loadPrevZTDataTable"
            :row-key="(row) => row.id"
            ref="actionRef"
            :actionColumn="false"
            :checked-row-keys="checkedIds"
            @update:checked-row-keys="onCheckedRow"
            :scroll-x="1090"
            :resizeHeightOffset="-10000"
            size="small"
          />
        </n-tab-pane>
        <n-tab-pane name="strong_em" tab="强势股">
          <BasicTable
            :openChecked="true"
            :columns="strongColumns"
            :request="loadStrongDataTable"
            :row-key="(row) => row.id"
            ref="actionRef"
            :actionColumn="false"
            :checked-row-keys="checkedIds"
            @update:checked-row-keys="onCheckedRow"
            :scroll-x="1090"
            :resizeHeightOffset="-10000"
            size="small"
          />
        </n-tab-pane>
        <n-tab-pane name="zbgc_em" tab="炸板股池">
          <BasicTable
            :openChecked="true"
            :columns="columns"
            :request="loadZBGCDataTable"
            :row-key="(row) => row.id"
            ref="actionRef"
            :actionColumn="false"
            :checked-row-keys="checkedIds"
            @update:checked-row-keys="onCheckedRow"
            :scroll-x="1090"
            :resizeHeightOffset="-10000"
            size="small"
          />
        </n-tab-pane>
        <n-tab-pane name="sub_new" tab="次新">
          <BasicTable
            :openChecked="true"
            :columns="subNewColumns"
            :request="loadSubNewDataTable"
            :row-key="(row) => row.id"
            ref="actionRef"
            :actionColumn="false"
            :checked-row-keys="checkedIds"
            @update:checked-row-keys="onCheckedRow"
            :scroll-x="1090"
            :resizeHeightOffset="-10000"
            size="small"
          />
        </n-tab-pane>
      </n-tabs>
    </n-card>
    <Edit @reloadTable="reloadTable" ref="editRef" />
    <View ref="viewRef" />
  </div>
</template>

<script lang="ts" setup>
  import { h, reactive, ref } from 'vue';
  import { useDialog, useMessage } from 'naive-ui';
  import { BasicTable, TableAction } from '@/components/Table';
  import { BasicForm, useForm } from '@/components/Form/index';
  import { usePermission } from '@/hooks/web/usePermission';
  import { List, Export, Delete, ZTList } from '@/api/stockAbnormalPool';
  import { columns, schemas, strongColumns, subNewColumns } from './model';
  import { PlusOutlined, ExportOutlined, DeleteOutlined } from '@vicons/antd';
  import { getOptionLabel } from '@/utils/hotgo';
  import Edit from './edit.vue';
  import View from './view.vue';

  const dialog = useDialog();
  const message = useMessage();
  const { hasPermission } = usePermission();
  const actionRef = ref();
  const searchFormRef = ref<any>({});
  const viewRef = ref();
  const editRef = ref();
  const batchDeleteDisabled = ref(true);
  const checkedIds = ref([]);

  const [register, {}] = useForm({
    gridProps: { cols: '1 s:1 m:2 l:3 xl:4 2xl:4' },
    labelWidth: 80,
    schemas,
  });

  // 跌停
  const loadDTDataTable = async (res) => {
    return await ZTList({ type: 3, ...res });
  };
  // 昨日涨停
  const loadPrevZTDataTable = async (res) => {
    return await ZTList({ type: 2, ...res });
  };
  // 涨停
  const loadZTDataTable = async (res) => {
    return await ZTList({ type: 1, ...res });
  };
  // 强势股
  const loadStrongDataTable = async (res) => {
    return await List({ type: 1, ...res });
  };
  // 次新
  const loadSubNewDataTable = async (res) => {
    return await List({ type: 2, ...res });
  };
  // 炸板
  const loadZBGCDataTable = async (res) => {
    return await List({ type: 3, ...res });
  };
  function onCheckedRow(rowKeys) {
    batchDeleteDisabled.value = rowKeys.length <= 0;
    checkedIds.value = rowKeys;
  }

  function reloadTable() {
    actionRef.value.reload();
  }

  function addTable() {
    editRef.value.openModal(null);
  }

  function handleEdit(record: Recordable) {
    editRef.value.openModal(record);
  }

  function handleView(record: Recordable) {
    viewRef.value.openModal(record);
  }

  function handleDelete(record: Recordable) {
    dialog.warning({
      title: '警告',
      content: '你确定要删除？',
      positiveText: '确定',
      negativeText: '取消',
      onPositiveClick: () => {
        Delete(record).then((_res) => {
          message.success('删除成功');
          reloadTable();
        });
      },
    });
  }

  function handleBatchDelete() {
    dialog.warning({
      title: '警告',
      content: '你确定要批量删除？',
      positiveText: '确定',
      negativeText: '取消',
      onPositiveClick: () => {
        Delete({ id: checkedIds.value }).then((_res) => {
          batchDeleteDisabled.value = true;
          checkedIds.value = [];
          message.success('删除成功');
          reloadTable();
        });
      },
    });
  }

  function handleExport() {
    message.loading('正在导出列表...', { duration: 1200 });
    Export(searchFormRef.value?.formModel);
  }
</script>

<style lang="less" scoped></style>
